/* ==========================================================================
 * MATLAB C++ matfile generator class v0.1
 * ==========================================================================
 * Copyright (C) 2013 - Ericson Norberto A Santos (ericsonnorberto@gmail.com)
 * Federal University Of Campina Grande - UFCG
 * 
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Based on "Portable ANSI C MATLAB file exporter" by Malcolm McLean
 * http://www.malcolmmclean.site11.com/www/MatlabFiles/matfiles.html
 * Copyright (c) Malcolm McLean
*/
#include <cstdlib>

#include "MAT_file.hpp"

using namespace std;

double GetRandomNumber(double Lowest, double Highest);

int main(int argc, char** argv)
{
    /* 10x10 random matrix */
    double m_data1[100];
    /* 25x15 random matrix */
    double m_data2[375];
    
    
    /* Initializes Random number generator */
    srand((unsigned)time(0));
    
    /* Matrix m_data1 */
    for (int i=0; i<100; i++)
    {
        m_data1[i] = (i*GetRandomNumber(0, 5))/1000;
    }
    
    /* Matrix m_data2 */
    for (int j=0; j<375; j++)
    {
        m_data2[j] = (j*GetRandomNumber(6, 10))/1000;
    }
    
    /* New MAT_file object */
    MAT_file mat_file;

    /* Creates a new .mat file */
    mat_file.MATLAB_new_mat_file("./arquivos/arquivo.mat");
    
    /* Save m_data1 */
    mat_file.MATLAB_write_matrix_data("m_data1", m_data1, 10, 10, 0);
    
    /* Save m_data2 */
    mat_file.MATLAB_write_matrix_data("m_data2", m_data2, 25, 15, 0);

    /* Save single data string */
    mat_file.MATLAB_write_single_data_string("m_data3", "MATLAB C++ mt_file class");
    
    return EXIT_SUCCESS;
}

double GetRandomNumber(double Lowest, double Highest)
{
    double tmpRandomInt;
    double tmpRange = (Highest-Lowest)+1;
    
    tmpRandomInt = Lowest+double(tmpRange*rand()/(RAND_MAX+1.0));
    
    return tmpRandomInt;
}